<?php

namespace app\common\model;

use think\Model;


class Special extends Model
{

    // 表名
    protected $name = 'special_area';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [];

    protected static function init()
    {
        self::beforeInsert(function ($row) {
            $changed = $row->getChangedData();
            if (isset($changed['city_id'])) {
                $row->city = Area::where('id', $changed['city_id'])->value('name');
            }
        });
        self::beforeUpdate(function ($row) {
            $changed = $row->getChangedData();
            if (isset($changed['city_id'])) {
                $row->city = Area::where('id', $changed['city_id'])->value('name');
            }
        });
    }

    public function setCityAttr($v, $d)
    {
        return Area::where('id', $d['city_id'])->value('name');
    }
}
